package ru.nsu.fit.client.core.commands;

import ru.nsu.fit.client.core.log_manager.realization.KernelLogManager;
import ru.nsu.fit.client.core.response.KernelResponse;
import ru.nsu.fit.client.core.soap.get_questions_stat.GetQuestionsStat;
import ru.nsu.fit.client.core.soap.get_questions_stat.GetQuestionsStatOutput;

import java.util.List;

public class GetQuestionsStatCommand implements IClientCommand {
    private final long userSessionId;
    private final String serverUrl;
    private final List<Integer> ids;

    public GetQuestionsStatCommand(final String serverUrl, final long userSessionId, List<Integer> ids)
    {
        this.userSessionId = userSessionId;
        this.serverUrl = serverUrl;
        this.ids = ids;
    }

    @Override
    public KernelResponse execute() {
        try
        {
            KernelLogManager.print("Getting question stats...");
            GetQuestionsStatOutput output = GetQuestionsStat.execute(serverUrl, userSessionId, ids);

            KernelLogManager.print("Getting question stats - got response!");
            KernelResponse response = new KernelResponse(false);
            response.setErrorCode(output.getErrorCode());
            response.setErrorText(output.getErrorMessage());
            response.setData(output.getData());

            return response;
        }
        catch (Exception e)
        {
            KernelLogManager.printf("Getting question stats - web service error: %s", e.getMessage());
            KernelResponse response = new KernelResponse(false);
            response.setErrorText(e.getMessage());
            return response;
        }
    }
}
